package com.UdpRecieve.controller;

import com.UdpRecieve.domain.system.SysUser;
import com.UdpRecieve.service.SysIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
public class IndexController {



    @Autowired
    private SysIndexService sysIndexService;

    @GetMapping("/")
    public ModelAndView toConfigPage(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("redirect:login");
        return mv;
    }

    @GetMapping("/pageIndex")
    public ModelAndView toIndex(HttpServletRequest request){
        ModelAndView mv = new ModelAndView();
        SysUser user = sysIndexService.getOnlineUser(request.getSession().getId());
        mv.addObject("sysUser",user);
        System.out.println(user);
        mv.setViewName("index");
        return mv;
    }

    @GetMapping("/error")
    public ModelAndView toErrorPage(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("error");
        return mv;
    }

    @GetMapping("/main")
    public ModelAndView toMain(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("main");
        return mv;
    }
}
